import { useState, useEffect, useRef } from 'react';
import { PageContainer } from '@ant-design/pro-layout';
import { useRequest } from 'umi';
import {
  Button,
  Descriptions,
  Result,
  Avatar,
  Space,
  Statistic,
  Modal,
  Form,
  Input,
  Select,
} from 'antd';
import ProTable from '@ant-design/pro-table';
import {
  MinusCircleOutlined,
  PlusOutlined,
  EditOutlined,
  CloseCircleOutlined,
  UserOutlined,
  BarChartOutlined,
  StockOutlined,
} from '@ant-design/icons';

import {
  ModalForm,
  ProFormText,
  ProFormTextArea,
} from '@ant-design/pro-components';
import { ActionType } from '@ant-design/pro-table';

const { Option } = Select;

const DirectionManagement = () => {
  const [form] = Form.useForm();

  //获取所有方向
  const findAllDirection = useRequest(
    (data = null) => {
      return {
        url: 'http://10.1.40.84:9993/direction/findAllDirection',
        method: 'POST',
        headers: {
          Authorization: localStorage.getItem('token') || '',
        },
        data,
      };
    },
    {
      manual: true,
    },
  );

  const insertDirection = useRequest(
    (data = null) => {
      return {
        url: 'http://10.1.40.84:9993/direction/insertDirection',
        method: 'POST',
        headers: {
          Authorization: localStorage.getItem('token') || '',
        },
        data,
      };
    },
    {
      manual: true,
    },
  );

  const updateDirection = useRequest(
    (data = null) => {
      return {
        url: 'http://10.1.40.84:9993/direction/updateDirection',
        method: 'POST',
        headers: {
          Authorization: localStorage.getItem('token') || '',
        },
        data,
      };
    },
    {
      manual: true,
    },
  );

  useEffect(() => {
    findAllDirection.run();
  }, []);

  //修改后
  const columnsChanged: any = [
    {
      title: '成果名称',
      dataIndex: 'Name',
      key: 'Name',
    },
    {
      title: '成果类型',
      dataIndex: 'type',
      key: 'type',
      hideInSearch: true,
      // copyable: true,
    },
    {
      title: '被拒原因',
      dataIndex: 'message',
      key: 'message',
      hideInSearch: true,
    },
    {
      title: '拒绝者名称',
      dataIndex: 'people',
      key: 'people',
      hideInSearch: true,
    },
    {
      title: '时间',
      dataIndex: 'time',
      key: 'time',
      hideInSearch: true,
    },
    {
      title: '操作',
      valueType: 'option',
      key: 'option',
      align: 'center',
      render: (text: any, record: any, _: any, action: any) => [
        <Button
          type="link"
          key="edit"
          onClick={() => {
            // form.setFieldsValue(record);
            // setEditVisible(true);
          }}
        >
          编辑
        </Button>,
      ],
    },
  ];

  const dataSource: any = [
    {
      key: '1',
      Name: '名称名称名称名称名称名称名称名称名称',
      type: '论文',
      message: '提交材料与实际不符，需要重新审核',
      people: '李奎',
      time: '2022-04-03',
    },
    {
      key: '2',
      Name: '名称名称名称名称名称名称名称名称名称',
      type: '项目',
      message: '提交材料与实际不符，需要重新审核',
      people: '李奎',
      time: '2022-04-03',
    },
    {
      key: '3',
      Name: '名称名称名称名称名称名称名称名称名称',
      type: '项目',
      message: '提交材料与实际不符，需要重新审核',
      people: '李奎',
      time: '2022-04-03',
    },
  ];

  return (
    <PageContainer>
      <ProTable
        headerTitle={'方向列表'}
        // request={async () => {
        //     var tabledata: any = [];
        //     findAllDirection.run().then((data) => {
        //         tabledata = data;
        //     });
        //     return { data: tabledata, success: true };
        // }}
        columns={columnsChanged}
        dataSource={dataSource}
        rowKey="key"
        toolBarRender={() => [
          <Button
            type="primary"
            icon={<PlusOutlined />}
            onClick={() => {
              console.log('?');
            }}
          >
            添加方向
          </Button>,
        ]}
      />
    </PageContainer>
  );
};
export default DirectionManagement;
